<template>
  <div class="teacher-dashboard">
    <!-- 顶部信息 -->
    <div class="header">
      <div class="teacher-info">
        <div class="avatar">👨‍🏫</div>
        <div class="info">
          <h1>{{ teacherInfo.name }}</h1>
          <p>{{ teacherInfo.department }} | {{ teacherInfo.title }}</p>
        </div>
      </div>
      <div class="logout-btn" @click="handleLogout">
        退出登录
      </div>
    </div>

    <!-- 统计卡片 -->
    <div class="stat-cards">
      <div v-for="stat in stats" :key="stat.id" class="stat-card">
        <div class="stat-icon" :style="{ background: stat.color }">{{ stat.icon }}</div>
        <div class="stat-info">
          <h3>{{ stat.title }}</h3>
          <div class="stat-value">{{ stat.value }}</div>
        </div>
      </div>
    </div>

    <!-- 我的课程 -->
    <div class="section">
      <div class="section-header">
        <h2>我的课程</h2>
        <button class="add-btn">
          <span class="icon">+</span> 添加课程
        </button>
      </div>
      <div class="course-grid">
        <div v-for="course in courses" 
             :key="course.id" 
             class="course-card"
             @click="goToCourse(course.id)">
          <div class="course-icon">📚</div>
          <div class="course-info">
            <h3>{{ course.name }}</h3>
            <p>{{ course.schedule }}</p>
          </div>
          <div class="course-stats">
            <div class="stat">
              <span class="label">班级数</span>
              <span class="value">{{ course.classCount }}</span>
            </div>
            <div class="stat">
              <span class="label">学生数</span>
              <span class="value">{{ course.studentCount }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 班级管理 -->
    <div class="section">
      <div class="section-header">
        <h2>班级管理</h2>
      </div>
      <div class="class-grid">
        <div v-for="class_ in classes" 
             :key="class_.id" 
             class="class-card"
             @click="goToClass(class_.id)">
          <div class="class-header">
            <div class="class-name">{{ class_.name }}</div>
            <div class="class-course">{{ class_.course }}</div>
          </div>
          <div class="class-stats">
            <div class="stat">
              <span class="label">学生数</span>
              <span class="value">{{ class_.studentCount }}</span>
            </div>
            <div class="stat">
              <span class="label">平均分</span>
              <span class="value">{{ class_.avgScore }}</span>
            </div>
          </div>
          <div class="class-progress">
            <div class="progress-label">课程进度</div>
            <div class="progress-bar">
              <div class="progress" :style="{ width: class_.progress + '%' }"></div>
            </div>
            <div class="progress-value">{{ class_.progress }}%</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const teacherInfo = ref({
  name: '张老师',
  department: '计算机科学与技术学院',
  title: '副教授'
})

const stats = ref([
  {
    id: 1,
    title: '课程数',
    value: '5',
    icon: '📚',
    color: '#1890ff'
  },
  {
    id: 2,
    title: '班级数',
    value: '8',
    icon: '👥',
    color: '#52c41a'
  },
  {
    id: 3,
    title: '学生总数',
    value: '246',
    icon: '👨‍🎓',
    color: '#722ed1'
  },
  {
    id: 4,
    title: '平均分',
    value: '85.6',
    icon: '📊',
    color: '#faad14'
  }
])

const courses = ref([
  {
    id: 1,
    name: '数据结构',
    schedule: '周一 1-2节',
    classCount: 3,
    studentCount: 90
  },
  {
    id: 2,
    name: '计算机网络',
    schedule: '周三 3-4节',
    classCount: 2,
    studentCount: 60
  },
  // ... 更多课程
])

const classes = ref([
  {
    id: 1,
    name: '计算机科学1班',
    course: '数据结构',
    studentCount: 30,
    avgScore: 85.5,
    progress: 75
  },
  {
    id: 2,
    name: '软件工程2班',
    course: '计算机网络',
    studentCount: 32,
    avgScore: 83.2,
    progress: 68
  },
  // ... 更多班级
])

const goToCourse = (courseId) => {
  router.push(`/teacher/course/${courseId}`)
}

const goToClass = (classId) => {
  router.push(`/teacher/class/${classId}`)
}

const handleLogout = () => {
  localStorage.removeItem('user')
  router.push('/login')
}
</script>

<style scoped>
.teacher-dashboard {
  min-height: 100vh;
  background: #f0f2f5;
  padding: 30px;
}

.header {
  background: white;
  border-radius: 12px;
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.teacher-info {
  display: flex;
  align-items: center;
  gap: 20px;
}

.avatar {
  font-size: 48px;
  background: #f0f2f5;
  width: 80px;
  height: 80px;
  border-radius: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logout-btn {
  padding: 8px 16px;
  background: #ff4d4f;
  color: white;
  border-radius: 6px;
  cursor: pointer;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.section {
  background: white;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.add-btn {
  padding: 8px 16px;
  background: #1890ff;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.course-grid, .class-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.course-card, .class-card {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.course-card:hover, .class-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.progress-bar {
  height: 8px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0;
}

.progress {
  height: 100%;
  background: #1890ff;
  border-radius: 4px;
}
</style> 